<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        .tab {
            width: 100%;
            height: 700px;
        }

        .tab-container {
            width: 100%;
            list-style: none;
        }

        ul {
            height: 100px;
            display: flex;
            align-items: center;
            flex-direction: row;
            background-color: rgb(169, 196, 169);
            justify-content: space-between;
        }

        li {
            list-style: none;
        }
        .current{
            background-color: red;
        }
        .item{
            display: none;
        }
        .block{
            display: block;
        }
        
    </style>
</head>

<body>
    <div class="tab">
        <div class="tab-container">
            <ul>
                <li>商品介绍</li>
                <li>规格与包装</li>
                <li>售后保障</li>
                <li>商品评价</li>
                <li>手机社区</li>
            </ul>
        </div>
        <div class="tab-body">
            <div class="item">商品介绍栏</div>
            <div class="item">规格和包装内容</div>
            <div class="item">售后保障</div>
            <div class="item">商品评价</div>
            <div class="item">手机社区</div>
        </div>
    </div>
    <script>
        let con = document.querySelector('.tab-container').querySelectorAll('li');
        let sum = document.querySelector('.tab-body').querySelectorAll('div')
        console.log(con);
        for( var i = 0; i < con.length;i++){
            //给每个li设置一个索引号
            con[i].setAttribute('index',i)
            con[i].onclick = function(){
                for(var i = 0; i <con.length; i++){
                    // con[1].className = 'current'
                    con[i].className = ''
                }
                this.className = 'current';
                //获取到当前的li的自定义索引号，然后通过排他思想将所有的属性设置为none
                 let index = this.getAttribute('index');
                 console.log(index);
                 for(var i = 0; i< sum.length; i++){
                     sum[i].style.display = 'none'
                }
                //将当前点击的li的属性设置为显示
                sum[index].style.display = 'block';
            }
        }
    </script>
</body>

</html>